import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * 目标：完成遍历集合案例
 */
public class Test4MovieForeach {

    public static void main(String[] args) {
        // 创建Collection集合来存储电影
        Collection<Movie> movies = new ArrayList<>();

        // 添加5部科幻电影
        movies.add(new Movie("星际穿越", 9.3, "¥45", "马修·麦康纳"));
        movies.add(new Movie("盗梦空间", 9.0, "¥40", "莱昂纳多·迪卡普里奥"));
        movies.add(new Movie("阿凡达", 8.8, "¥50", "萨姆·沃辛顿"));
        movies.add(new Movie("黑客帝国", 9.1, "¥35", "基努·里维斯"));
        movies.add(new Movie("银翼杀手2049", 8.3, "¥42", "瑞恩·高斯林"));


        //需求：三种方式，遍历集合中的电影信息
        Iterator<Movie> iterator = movies.iterator();
        while (iterator.hasNext()){
            Movie movie = iterator.next();
            System.out.println(movie.toString());
        }
        for (Movie movie : movies){
            System.out.println(movie.toString());
        }
        movies.forEach(new Consumer<Movie>() {
            @Override
            public void accept(Movie movie) {

            }
        });
        movies.forEach(movie -> System.out.println(movie.toString()));



    }
}


class Movie{
    private String name;
    private double score;
    private String price;
    private String actor;

    public Movie(String name, double score, String price, String actor) {
        this.name = name;
        this.score = score;
        this.price = price;
        this.actor = actor;
    }

    @Override
    public String toString() {
        return "Movie{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", price='" + price + '\'' +
                ", actor='" + actor + '\'' +
                '}';
    }
}